﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GUI
{
    public partial class FormClassificationCapacity : Form
    {
        public FormClassificationCapacity()
        {
            InitializeComponent();
        }

        //全局变量
        int rowIndex;


        private void FormClassificationCapacity_Load(object sender, EventArgs e)
        {
            dataGridView1.AllowUserToAddRows = false;

            this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells;

            dataGridView1.Columns.Add("number ", "序号");
            dataGridView1.Columns.Add("grade", "等级分类");


        }




        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {

        }
        //dgv 添加时间查询条件
        private void checkBox11_CheckedChanged(object sender, EventArgs e)
        {

            if (checkBox11.CheckState == CheckState.Checked)
            {
                dataGridView1.Columns.Add("time1", "时间<");
                dataGridView1.Columns.Add("time2", "时间>=");
            }
            else
            {
                string columnName = "time1"; // 要删除的列的名称
                dataGridView1.Columns.Remove(columnName);

                string columnName2 = "time2"; 
                dataGridView1.Columns.Remove(columnName2);
            }

        }

        //dgv 添加容量查询条件
        private void checkBox12_CheckedChanged(object sender, EventArgs e)
        {          
            if (checkBox12.CheckState == CheckState.Checked)
            {
                dataGridView1.Columns.Add("capacity1", "容量<");
                dataGridView1.Columns.Add("capacity2", "容量>=");
            }
            else
            {
                string columnName = "capacity1"; //要删除的列的名称
                dataGridView1.Columns.Remove(columnName);

                string columnName2 = "capacity2";
                dataGridView1.Columns.Remove(columnName2);
            }
        }

        //dgv 添加电压查询条件
        private void checkBox13_CheckedChanged(object sender, EventArgs e)
        {
           

            if (checkBox13.CheckState == CheckState.Checked)
            {
                dataGridView1.Columns.Add("voltage1", "电压<");
                dataGridView1.Columns.Add("voltage2", "电压>=");
            }
            else
            {
                string columnName = "voltage1"; // 要删除的列的名称
                dataGridView1.Columns.Remove(columnName);

                string columnName2 = "voltage2";
                dataGridView1.Columns.Remove(columnName2);
            }

        }

        int maxIndex = 0;

        //添加新的分容等级
        private void 增加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Console.WriteLine("增加");
            //int currentMaxIndex = Convert.ToInt32(dataGridView1["number", dataGridView1.NewRowIndex].Value);
            //获取当前行数
            int currentMaxIndex = dataGridView1.Rows.Count;

            int index = this.dataGridView1.Rows.Add();
            this.dataGridView1.Rows[index].Cells[0].Value = ++currentMaxIndex;


        }

        //删除最后一个分容等级
        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            //删除最后一行
            
            int currentMaxIndex = dataGridView1.Rows.Count;//获取当前行数
            if (dataGridView1.Rows.Count > 0)
            {              
                if (MessageBox.Show(this, "警告:确定删除？", "警告", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    this.dataGridView1.Rows.RemoveAt(--currentMaxIndex);
                }

            }


            //删除鼠标选定行
            /* if (dataGridView1.SelectedRows.Count > 0)
             {
                 int selectedRowIndex = dataGridView1.CurrentCellAddress.Y;

                 Console.WriteLine("删除行号：" + selectedRowIndex);

                 if (MessageBox.Show(this, "警告:确定删除？？？", "警告", MessageBoxButtons.OKCancel) == DialogResult.OK)
                 {
                     this.dataGridView1.Rows.RemoveAt(selectedRowIndex);
                 }

             }*/

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
